﻿using System.Linq;

namespace NeGroid.ChampionshipManager.Persistance
{
	public static class SortExtensions
	{
		public static IQueryable<T> OrderBy<T>(this IQueryable<T> datasource, SortOptions sortOptions)
		{
			var orderByCall = QueryHelper.GenerateMethodCall(datasource,
				sortOptions.Direction == SortDirection.Ascending
					? "OrderBy"
					: "OrderByDescending", sortOptions.PropertyName);

			return datasource.Provider.CreateQuery<T>(orderByCall);
		}
	}
}
